package com.sk.commonadapter_android;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;

import com.sk.commonadapter_android.adapter.CommonMultiTypeRecyclerViewAdapter;
import com.sk.commonadapter_android.adapter.CommonViewHolder;
import com.sk.commonadapter_android.adapter.MultiTypeSupport;
import com.sk.commonadapter_android.bean.Chart;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author yemao
 * @Email yrmao9893@163.com
 * @Date 2017/6/13
 * @Des null!
 */

public class CommonMutliTypeActivity extends AppCompatActivity {
    private RecyclerView mRecyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_common_recyclerview);
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        List<Chart> mData = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            if (i % 5 == 0) {
                mData.add(new Chart(1, "我是内容" + i));
            } else if (i%7==0){
                mData.add(new Chart(2, "我是内容" + i));
            }else {
                mData.add(new Chart(3, "我是内容" + i));
            }
        }
        mAdapter.addAll(mData);
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL));
        mRecyclerView.setAdapter(mAdapter);
    }

    CommonMultiTypeRecyclerViewAdapter<Chart> mAdapter = new CommonMultiTypeRecyclerViewAdapter<Chart>(this, -1, new MultiTypeSupport<Chart>() {
        @Override
        public int getLayoutId(Chart chart) {
            if (chart.getType()==1){
                return R.layout.item_chart_me;
            }else if (chart.getType()==2){
                return R.layout.item_chart_other;
            }else {
                return R.layout.item_common_recyclerview;
            }

        }
    }) {
        @Override
        public void convert(CommonViewHolder holder, Chart item, int position) {
            if (item.getType()!=3){
                holder.setTextView(R.id.tv_chart, item.getDes());
            }else {
                holder.setTextView(R.id.tv_comm_value, item.getDes());
            }

        }
    };
}